import 'dart:convert';
import 'package:dart_sm/dart_sm.dart';

String generateHashString(String inputStr) {
  // 出于安全性考虑，这里直接返回固定值，请开发者自行实现生成算法
  return "0123456789abcdef";
}

List<String> generateHexStrings(String inputStr) {
  // 出于安全性考虑，这里直接返回固定值，请开发者自行实现生成算法
  return ["fedcba98765432100123456789abcdef", "fedcba98765432100123456789abcdef"];
}

class Encryption {
  static String _key = ""; // 密钥
  static String _iv = ""; // 偏移量

  static void init(String inputStr) {
    List<String> hexStrings = generateHexStrings(inputStr);
    _key = hexStrings[0];
    _iv = hexStrings[1];
    SM4.setKey(_key);
  }

  static String encryptPass(Map<String, dynamic> data) {
    return SM4.encrypt(
      jsonEncode(data),
      mode: SM4CryptoMode.CBC,
      iv: _iv,
    );
  }

  static Map<String, dynamic> decryptPass(String data) {
    return jsonDecode(SM4.decrypt(
      data,
      mode: SM4CryptoMode.CBC,
      iv: _iv,
    ));
  }
}
